home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-03-29 | 4.8 KB | 176 lines | [TEXT/CWIE] |
- // Copyright © 1995 Apple Computer, Inc. All rights reserved.
- // Release Version: $ 1.0 d8 $
-
- //=======================================================================
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- // ----- Framework Layer -----
- #ifndef FWUTIL_H
- #include "FWUtil.h" // FW_CFacetContext, FW_Beep()
- #endif
-
- // ----- OS Layer -----
- #ifndef FWMENU_H
- #include "FWMenu.h" // FW_CMenuBar, etc.
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h" // FW_CMenuEvent, FW_CMouseEvent
- #endif
-
- // ----- Graphic Includes -----
- #ifndef FWRECT_H
- #include <FWRect.h> // FW_CRect
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h" // FW_CRectShape
- #endif
-
- #ifndef FWPICSHP_H
- #include "FWPicShp.h" // FW_PPicture, FW_CPictureShape
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h" // FW_CViewContext
- #endif
-
- //=============================================================================
- #ifdef FW_BUILD_MAC
- #pragma segment Windoid
- #endif
-
- FW_DEFINE_AUTO(CMainFrame)
- //=============================================================================
- CMainFrame::CMainFrame(Environment* ev, ODFrame* odFrame,
- FW_CPresentation* presentation, CWindoidPart* part)
- : FW_CFrame(ev, odFrame, presentation, part)
- {
- FW_Boolean showPalette = this->IsRoot(ev);
- part->MyMakePalette(ev, showPalette);
- FW_END_CONSTRUCTOR
- }
-
- //------------------------------------------------------------------------------
- CMainFrame::~CMainFrame()
- {
- FW_START_DESTRUCTOR
- }
-
- //------------------------------------------------------------------------------
- void
- CMainFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_CViewContext context(ev, this, odFacet, invalidShape);
- FW_CRect box = this->GetBounds(ev);
- FW_CRectShape::RenderRect(context, box, FW_kFill, FW_kRGBGreen);
- }
-
- //=============================================================================
- const short kNumberOfColumns = 6;
- const short kNumberOfRows = 1;
- const FW_Fixed kCellSizeV = FW_IntToFixed(42);
- const FW_Fixed kCellSizeH = FW_IntToFixed(41);
-
- FW_DEFINE_AUTO(CPaletteFrame)
-
- //------------------------------------------------------------------------------
- CPaletteFrame::CPaletteFrame(Environment* ev, ODFrame* odFrame,
- FW_CPresentation* presentation, CWindoidPart* part)
- : FW_CFrame(ev, odFrame, presentation, part),
- fWindoidPart(part),
- fSelectedRow(0),
- fSelectedCol(0)
- {
- this->SetCanBeActiveFrame(ev, false);
- FW_END_CONSTRUCTOR
- }
-
- //------------------------------------------------------------------------------
- CPaletteFrame::~CPaletteFrame()
- {
- FW_START_DESTRUCTOR
- }
-
- //------------------------------------------------------------------------------
- void
- CPaletteFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_CViewContext context(ev, this, odFacet, invalidShape);
- FW_CRect box = this->GetBounds(ev);
-
- // Draw Picture that looks like a list of Icons
- FW_CSharedLibraryResourceFile resFile(ev);
- FW_CPicture pict(resFile, kPalettePictID);
- FW_CPictureShape shape(pict, box);
- shape.Render(context);
-
- // Indicate "selected" Icon
- FW_CRect rect;
- this->GetCellRectangle(fSelectedRow, fSelectedCol, rect);
- FW_CRectShape rectShape(rect, FW_kFrame);
- rectShape.Render(context);
- }
-
- //------------------------------------------------------------------------------
- FW_Boolean
- CPaletteFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- // Get the mouse in local coordinates
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
-
- // See what cell was hit and store in frame
- if (this->FindCell(where, fSelectedRow, fSelectedCol)) {
- FW_CRect frameRect = this->GetBounds(ev);
- this->Invalidate(ev, frameRect);
- }
- return TRUE; // we handled event
- }
-
- //------------------------------------------------------------------------------
- FW_Boolean
- CPaletteFrame::FindCell(const FW_CPoint& where, unsigned short& row,
- unsigned short& column) const
- {
- // Iterate over rows and columns and see if a cell was hit
- FW_CRect rect;
- for (unsigned short x = 0; x < kNumberOfColumns; x++)
- for (unsigned short y = 0; y < kNumberOfRows; y++)
- {
- // calculate geometry of this grid cell
- this->GetCellRectangle(y, x, rect);
- if (rect.Contains(where))
- {
- // got one
- column = x;
- row = y;
- return TRUE;
- }
- }
-
- return FALSE;
- }
- //------------------------------------------------------------------------------
- void
- CPaletteFrame::GetCellRectangle(unsigned short row, unsigned short column,
- FW_CRect& rect) const
- {
- // Get geometry of a cell in a grid
- rect.Set(FW_IntToFixed(0),FW_IntToFixed(0), kCellSizeH, kCellSizeV);
- rect.Place(kCellSizeH * FW_IntToFixed(column), kCellSizeV * FW_IntToFixed(row) );
- }
-